//
//  NewTuiGuangInfoViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2018/3/29.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "NewTuiGuangInfoViewController.h"
#import "TYCyclePagerView.h"
#import "JTCSM.h"
#import "NewTuiGuangInfoCollectionViewCell.h"
#import "NewSetErweiMaViewController.h"

@interface NewTuiGuangInfoViewController ()<TYCyclePagerViewDataSource, TYCyclePagerViewDelegate>
@property (nonatomic, strong) TYCyclePagerView *pagerView;
@property (nonatomic,strong) NSMutableArray *datas;

@end

@implementation NewTuiGuangInfoViewController

- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [df isRemoveTarbar:YES];
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor =[UIColor whiteColor];
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    // Do any additional setup after loading the view.
    [self addPagerView];
    [self loadData];
}

-(void)addPagerView {
    TYCyclePagerView *pagerView = [[TYCyclePagerView alloc]init];
    pagerView.frame = CGRectMake(0, 30, CGRectGetWidth(self.view.frame), KCONTROLLERHeight-200);
    pagerView.dataSource = self;
    pagerView.delegate = self;
    [pagerView registerClass:[NewTuiGuangInfoCollectionViewCell class] forCellWithReuseIdentifier:@"tuiguangcell"];
    [self.view addSubview:pagerView];
    _pagerView = pagerView;
    
    UIButton *tijiaobutton = [UIButton buttonWithType:UIButtonTypeCustom];
    tijiaobutton.frame = CGRectMake(25, KVIEW_Y(pagerView)+30, KCONTROLLERWith-40, 50);
    [tijiaobutton addTarget:self action:@selector(tijiao) forControlEvents:UIControlEventTouchUpInside];
    [df layerWithView:tijiaobutton radius:5 width:0 color:nil];
    tijiaobutton.backgroundColor = KZhuTiRGB;
    [tijiaobutton setTitleColor:RGBACOLOR(51, 51, 51, 1) forState:UIControlStateNormal];
    [tijiaobutton setTitle:@"制作二维码" forState:UIControlStateNormal];
    [self.view addSubview:tijiaobutton];
    
}

- (void)tijiao{
    NewSetErweiMaViewController *vc = [[NewSetErweiMaViewController alloc]init];
    vc.nameTitle = @"生成二维码";
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)loadData {
    
    _datas = [@[@""] copy];
    [_pagerView reloadData];
    _pagerView.isInfiniteLoop =YES;
    _pagerView.autoScrollInterval =0;
    _pagerView.layout.itemHorizontalCenter = NO;
    _pagerView.layout.layoutType = TYCyclePagerTransformLayoutLinear;
    _pagerView.layout.itemSize = CGSizeMake(CGRectGetWidth(_pagerView.frame)*0.8, CGRectGetHeight(_pagerView.frame)*0.93);
    _pagerView.layout.itemSpacing =0;
    [_pagerView setNeedUpdateLayout];
}

#pragma mark - TYCyclePagerViewDataSource

- (NSInteger)numberOfItemsInPagerView:(TYCyclePagerView *)pageView {
    return _datas.count;
}

- (UICollectionViewCell *)pagerView:(TYCyclePagerView *)pagerView cellForItemAtIndex:(NSInteger)index {
    NewTuiGuangInfoCollectionViewCell *cell = [pagerView dequeueReusableCellWithReuseIdentifier:@"tuiguangcell" forIndex:index];
    return cell;
}

- (TYCyclePagerViewLayout *)layoutForPagerView:(TYCyclePagerView *)pageView {
    TYCyclePagerViewLayout *layout = [[TYCyclePagerViewLayout alloc]init];
    layout.itemSize = CGSizeMake(CGRectGetWidth(pageView.frame)*0.8, CGRectGetHeight(pageView.frame)*0.93);
    layout.itemSpacing =0;
    //    layout.minimumAlpha = 0.3;
    layout.itemHorizontalCenter = NO;
    return layout;
}

- (void)pagerView:(TYCyclePagerView *)pageView didScrollFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex {

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
